package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/net/ghttp"
	"time"
)

func main() {
	s := g.Server()
	s.SetSessionMaxAge(time.Minute * 10)
	s.Group("session", func(group *ghttp.RouterGroup) {
		key := "my_user_name2"
		group.GET("/set", func(r *ghttp.Request) {
			r.Session.Set(key, "gary")
			r.Response.Write("set session name")
		})
		group.GET("/get", func(r *ghttp.Request) {
			name, _ := r.Session.Get(key)
			r.Response.Writef("get session name:%v", name)
		})
		group.GET("/remove", func(r *ghttp.Request) {
			r.Session.Remove(key)
			r.Response.Write("remove session name")
		})
	})
	//s.BindHandler("/session", func(r *ghttp.Request) {
	//	myDate := r.Cookie.Get("myDate")
	//	r.Cookie.SetCookie("myDate", "test:2019-01-01", "", "/", 0)
	//	r.Response.Writef("myDate:%v", myDate)
	//})
	s.SetPort(8101)
	s.Run()
}
